import Vue from 'vue';
import Vuex from 'vuex';

import StudentModule from './student-module';
import CoachModule from './coach-module';
import $https from '@/api/https';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    AccountInfo: {},        // 当前学员的账户信息
  },
  mutations: {
    setAccountInfo(state, val) { // 设置账户信息
      state.AccountInfo = val
    }
  },
  actions: {
    // 根据 [identify] 属性获取【账户信息】
    async getAccountInfo(context) {
      const { data } = await $https.verifyLogin({
        username: JSON.parse(localStorage.getItem("token")).username
      });
      context.commit("setAccountInfo", data[0])
      return data[0]
    },
  },
  modules: {
    StudentModule,
    CoachModule
  },
});
